package huoye.shops.huoye.mine.presenter;


import android.util.Log;

import huoye.shops.base.BasePresenter;
import huoye.shops.base.MineBaseJsonRequestCallback;
import huoye.shops.huoye.mine.activity.EditAccoundActivity;
import huoye.shops.huoye.mine.model.AccountList;
import huoye.shops.huoye.mine.model.AddAccountInfo;
import huoye.shops.huoye.mine.model.AuthStateData;
import huoye.shops.huoye.mine.model.ShopDetials;
import huoye.shops.huoye.mine.networt.MineService;
import huoye.shops.huoye.mine.view.IAddAccoundCodeView;
import huoye.shops.huoye.mine.view.IShopMessageView;


/**
 * Created by uesr on 2017/7/19.
 */

public class AddAccoundCodePresenter extends BasePresenter<IAddAccoundCodeView> {


    private MineService mService;

    //新增时获取账户权限列表  (获取微信二维码)
    public void addAccountInfo(){
        mService.addAccountInfo( new MineBaseJsonRequestCallback<AddAccountInfo>(AddAccountInfo.class) {

            @Override
            public void onSuccess(AddAccountInfo addAccountInfo) {
                super.onSuccess(addAccountInfo);
                view.getCodeStr(addAccountInfo);
            }

            //网络请求失败
            @Override
            public void onFailure(String msg, String code, Throwable e) {
                super.onFailure(msg, code, e);
                view.makeToast(msg);

            }

            //加载结束
            @Override
            public void onNetworkFail() {
                super.onNetworkFail();
                view.onNetworkFail();
            }

            //加载中
            @Override
            public void onFinish() {
                super.onFinish();
                view.hideProcessingIndicator();
            }
        });
    }



    //获取授权状态
    public void getAuthState(String timeStamp){

        mService.getAuthState(timeStamp, new MineBaseJsonRequestCallback<AuthStateData>(AuthStateData.class) {

            @Override
            public void onSuccess(AuthStateData authStateData) {
                super.onSuccess(authStateData);
                view.getCodeReturn(authStateData);
            }

            //网络请求失败
            @Override
            public void onFailure(String msg, String code, Throwable e) {
                super.onFailure(msg, code, e);
               // view.makeToast(msg);
                if(msg.equals("授权失败")) {
                   // view.getCodeReturnFail();
                }


            }

            //加载结束
            @Override
            public void onNetworkFail() {
                super.onNetworkFail();
                view.onNetworkFail();
            }

            //加载中
            @Override
            public void onFinish() {
                super.onFinish();
                view.hideProcessingIndicator();
            }
        });
    }


    @Override
    public void onStart() {
        mService = new MineService();
    }
}
